package com.student.test;

import com.student.entity.Menu;
import com.student.realm.UserRealm;
import com.student.service.ManageService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * Created by zhudong on 2016/9/17.
 */
public class Init {

    public static void init(){
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext*.xml");
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext-db.xml");
        Menu menu = new Menu("用户管理","/user/list",0);
        ManageService manageService = (ManageService)applicationContext.getBean("manageService");
        manageService.save(Menu.class,menu);
    }

    public static void main(String[] args) {
//        init();
//        getAll();
        testRealm();
    }

    public static void getAll(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-db.xml");
        ManageService manageService = (ManageService)applicationContext.getBean("manageService");
        List<Menu> menus = (List<Menu>)manageService.getAll(Menu.class);
        for(Menu menu:menus){
            System.out.println(menu);
        }
    }

    public static void testRealm(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext-db.xml");
        UserRealm realm = (UserRealm)applicationContext.getBean("realm");
        System.out.println(realm);
    }
}
